﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL.Entities_BLL
{
    public class TaikhoanBLL:DAL.Entities_DAL.TaikhoanDAL
    {
        /// <summary>
        /// Mã tự sinh
        /// </summary>
        /// <param name="id"></param>
        /// <returns> id++ </returns>
        public string AddID(string id)
        {
            string s = id.Trim();

            int len = s.Length;
            string con = s.Substring(2);
            string kq = s.Substring(0, 2);
            int so = Convert.ToInt32(con) + 1;
            if (so <= 9)
                kq += '0';
            kq += so;

            return kq;
        }
        // kiem tra tai khoan
        public UTL.Session CheckLogin(string id, string pass)
        {
            string mk = pass;
            var usr = (DAL.Entities.Taikhoan)GetByKey(id);
            var sss = new UTL.Session();
            if (usr != null)
            {
                sss.Login = usr.MAT_KHAU == mk ? true : false;
                sss.Acc = usr.TEN_DANG_NHAP;
                sss.Pass = usr.MAT_KHAU;
                sss.Name = usr.hoten;
                sss.Role = (UTL.Session.Roles)usr.QUYEN_TRUY_CAP;
            }
            else sss.Login = false;
            return sss;
        }

    }
}
